<template>
  <div
    class="item-image-container"
    :class="index%2!=0?'container-1':'' "
    @click="linkHandler({title:itemData.title, link:itemData.cover, href:itemData.link})"
  >
    <!-- 封面布局组 -->
    <div class="img-layer-container">
      <!-- 封面 -->
      <div class="img-container">
        <vanImage :src="itemData.cover" class="cover">
          <template v-slot:loading>
            <van-loading type="spinner" size="20" />
          </template>
          <template v-slot:error>加载失败</template>
        </vanimage>
      </div>
      <div v-show="mivaShow">
        <img class="card-jiao card-jiao-l" :src="block_png">
        <img class="card-jiao card-jiao-r" :src="block_png">
      </div>
    </div>
    <!-- 标题组 -->
    <div class="title-layer-container">
      <div v-show="mivaShow" class="title title-l">
        <div class="title-body">{{ itemData.title }}</div>
      </div>
      <div class="title title-r">
        <div class="title-body">{{ itemData.title }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import default_png from '@/assets/default_long.png'
import A_block from '@/assets/A_block.png'
import A_block_black from '@/assets/A_block_black.png'
import { Image, loading } from 'vant'
export default {
  components: {
    vanImage: Image,
    vanLoading: loading
  },
  props: {
    user: {
      type: String,
      default: 'longImage'
    },
    index: {
      type: Number,
      required: false,
      default: 1
    },
    itemData: {
      type: Object,
      required: false,
      default() {
        return {
          title: '默认标题',
          cover: default_png
        }
      }
    }
  },
  computed: {
    block_png() {
      if (this.user === 'poster') {
        return A_block_black
      }
      return A_block
    },
    mivaShow() {
      return this.$store.state.mivaShow
    }
  },
  methods: {
    linkHandler(params) {
      const { itemData } = this
      if (params.href.indexOf('http') !== -1) {
        // return (window.location.href = params.href)
        return this.$router.push({
          path: 'webView',
          query: { title: itemData.title, url: itemData.link }
        })
      }
      this.$router.push({
        path: `/imageView`,
        query: { title: params.title, url: params.link }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.item-image-container {
  width: 40%;
  margin: 5%;
  height: 60vw;
  position: relative;
  display: inline-block;
  text-align: center;
  vertical-align: top;
  box-shadow: 0 0 5px #f45050;
  border-radius: 10px;
  overflow: hidden;
  background-color: #fafafa;
  color: #ae252b;
  &.container-1 {
    position: relative;
    top: calc(30vw);
  }
  @media (min-width: 640px) {
    & {
      padding-bottom: calc(640 * 0.6px) !important;
    }
    &.container-1 {
      top: calc(640 * 0.3px) !important;
    }
  }
  .card-jiao {
    width: 10%;
    position: absolute;
    &.card-jiao-l {
      top: 5px;
      left: 5px;
    }
    &.card-jiao-r {
      bottom: 5px;
      right: 5px;
      transform: rotateZ(180deg);
    }
  }
  .img-container {
    width: 70%;
    height: 90%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    overflow: hidden;
    .cover {
      width: 80%;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      border-radius: 10px;
      overflow: hidden;
    }
  }
  .title-layer-container {
    height: calc(60vw);
    max-height: calc(640 * 0.6px) !important;
    position: relative;
    z-index: 99;
    text-shadow: 1px 1px 1px #fff;
    font-weight: bold;
    font-size: 14px;
    word-wrap: break-word;
    .title {
      width: 15px;
      position: absolute;
    }
    .title-body {
      height: calc(60vw * 0.75);
      max-height: calc(640 * 0.6px * 0.75) !important;
      overflow-x: hidden;
      overflow-y: scroll;
    }
    .title-l {
      bottom: 3%;
      left: 4%;
      transform: rotateZ(180deg);
    }
    .title-r {
      top: 3%;
      right: 4%;
    }
  }
}
</style>

